# -*- coding:utf-8 -*-
# @FileName  :dhcc_per_2_authorize.py
# @Time      :2020/11/27 11:07
# @Author    :Zhoujirong
# @Desc      :个人授权信息维护
import datetime
import time
import parameterized
from biz.flow.per_authorize import PerAuthorizeRequest
from biz.flow.per_report import PerReportRequest
from biz.cases.base_case import BaseCase
from common.log import Log
from common.params_operator import Param


class TestPerAuthorize(BaseCase):
    '''个人授权文档管理'''
    data_file_name = 'per_authorize_data.yaml'

    @classmethod
    def setUpClass(cls):
        cls.cookie = BaseCase().get_token()
        cls.id = BaseCase().per_archive_create()

    @parameterized.parameterized.expand(Param.from_excel('authorize_data_pic.xls'))
    def test_aupload(self,file,fileType,md5,needMd5,check,desc):
        self._testMethodDoc = desc # 用例描述
        ret = PerAuthorizeRequest.upload(file,fileType,self.id,md5,needMd5,self.cookie)
        Log.info(ret)
        check=int(check)
        self.assertEqual(check,ret.code)

    def test_barchive_getpage(self):
        '''全条件检索'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_clientName = self.file_data.get('search_EQ_clientName')
        search_EQ_cretType = self.file_data.get('search_EQ_cretType')
        search_EQ_cretNo = self.file_data.get('search_EQ_cretNo')
        search_EQ_archiveType = self.file_data.get('search_EQ_archiveType')
        search_EQ_creator = self.file_data.get('search_EQ_creator')
        search_IN_ownorg = self.file_data.get('search_IN_ownorg')
        search_GTE_startDate_DATE = datetime.date.today()
        search_LTE_expireDate_DATE = datetime.date.today()
        EQ_queryNum = self.file_data.get('EQ_queryNum')
        ret = PerAuthorizeRequest.archive_getpage(curPage,
                            maxSize, search_EQ_clientName,
                            search_EQ_cretType,search_EQ_cretNo,
                            search_EQ_archiveType,search_EQ_creator,
                            search_IN_ownorg,search_GTE_startDate_DATE,
                            search_LTE_expireDate_DATE,EQ_queryNum,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)

    def test_carchive(self):
        '''查看有哪些授权文件'''
        ret = PerAuthorizeRequest.find_archive(self.id,self.cookie)
        Log.info(ret)
        self.assertEqual(4,len(ret))

    def test_dfindbyid(self):
        '''授权文件详情'''
        ret = PerAuthorizeRequest.findbyid(self.id,self.cookie)
        Log.info(ret)
        self.assertEqual(self.id,ret.id,'接口返回与预期不符')

    def test_earchive_update(self):
        '''编辑授权档案'''
        archiveType = self.file_data.get('archiveType')
        clientName = self.file_data.get('clientName')
        creatTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        creator = self.file_data.get('creator')
        cretNo = self.file_data.get('cretNo')
        cretType = self.file_data.get('cretType')
        expireDate = datetime.date.today()
        ext1 = self.file_data.get('ext1')
        ext2 = self.file_data.get('ext2')
        ext3 = self.file_data.get('ext3')
        ext4 = self.file_data.get('ext4')
        ext5 = self.file_data.get('ext5')
        ext6 = self.file_data.get('ext6')
        extendDate = datetime.date.today()
        note = self.file_data.get('note_update')
        operTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        operationIdentifier = self.file_data.get('operationIdentifier')
        operator = self.file_data.get('operator')
        operorg = self.file_data.get('operorg')
        ownorg = self.file_data.get('ownorg')
        quantity = self.file_data.get('quantity')
        queryNum = self.file_data.get('queryNum')
        remarks = self.file_data.get('remarks')
        reqId = self.file_data.get('reqId')
        resCode = self.file_data.get('resCode')
        resMsg = self.file_data.get('resMsg')
        serialNumber = self.file_data.get('serialNumber')
        startDate = datetime.date.today()
        status = self.file_data.get('status')
        paperfileid = self.file_data.get('paperfileid')
        filedescribe = self.file_data.get('filedescribe')
        ret = PerAuthorizeRequest.archive_update(archiveType,clientName,
                            creatTime,creator,
                            cretNo,cretType,
                            expireDate,ext1,
                            ext2,ext3,
                            ext4,ext5,
                            ext6,extendDate,
                            self.id,note,
                            operTime,operationIdentifier,
                            operator,operorg,
                            ownorg,quantity,
                            queryNum,remarks,
                            reqId,resCode,
                            resMsg,serialNumber,
                            startDate,status,
                            paperfileid,filedescribe,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)

    def test_esave_paper(self):
        '''保存授权文档'''
        paperfileid = self.file_data.get('paperfileid')
        filedescribe = self.file_data.get('filedescribe')
        archiveid = self.id
        ret = PerReportRequest.save_paper(paperfileid, filedescribe, archiveid, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code, '接口调用失败')
        return archiveid

    #添加纸质授权档案并删除流程
    def archive_create_paper(self):
        '''添加授纸质权档案'''
        archiveType = self.file_data.get('archiveType')
        Num = self.file_data.get('Num')
        clientName = self.file_data.get('clientName_paper')
        cretType = self.file_data.get('cretType')
        cretNo = self.file_data.get('cretNo')
        startDate = datetime.date.today()
        expireDate = datetime.date.today()
        note2 = self.file_data.get('note')
        paperfileid = self.file_data.get('paperfileid_paper')
        filedescribe = self.file_data.get('filedescribe_paper')
        ret = PerReportRequest.archive_create(archiveType, Num, clientName, cretType, cretNo, startDate, expireDate,
                                              note2, paperfileid, filedescribe, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        return ret.msg

    def save_paper(self):
        '''保存授权文档'''
        paperfileid = self.file_data.get('paperfileid_paper')
        filedescribe = self.file_data.get('filedescribe_paper')
        archiveid = self.archive_create_paper()
        ret = PerReportRequest.save_paper(paperfileid, filedescribe, archiveid, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code, '接口调用失败')
        return archiveid

    def test_farchive_del(self):
        '''删除授权信息和档案'''
        id = self.save_paper()
        ret = PerAuthorizeRequest.archive_del(id,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertIn('删除授权信息成功',ret.msg)


    #电子档案授权审批查询信用报告
    def per_inquire(self):
        '''查询本地是否有报告、同步授权'''
        clientName = self.file_data.get('clientName')
        certType = self.file_data.get('certType')
        certNo = self.file_data.get('certNo')
        assocbsnssData = self.file_data.get('assocbsnssData')
        note = self.file_data.get('note')
        queryFormat = '00'
        resultType = self.file_data.get('resultType')
        qryReason = self.file_data.get('qryReason')
        queryControlWarningType = self.file_data.get('queryControlWarningType')
        serialNumber = self.file_data.get('serialNumber')
        archiveId = self.id
        rekUser = self.file_data.get('rekUser')
        rekPasword = self.file_data.get('rekPasword')
        checkWay = self.file_data.get('checkWay')
        autharchiveId = archiveId
        ret = PerReportRequest.per_inquire(clientName, certType, certNo, assocbsnssData, note, queryFormat, resultType,
                                           qryReason,
                                           queryControlWarningType, serialNumber, archiveId, rekUser, rekPasword,
                                           checkWay, autharchiveId, self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.checkId)
        return ret.checkId

    def test_gshow_report(self):
        '''查询报告'''
        clientName = self.file_data.get('clientName')
        certType = self.file_data.get('certType')
        certNo = self.file_data.get('certNo')
        assocbsnssData = self.file_data.get('assocbsnssData')
        note = self.file_data.get('note')
        queryFormat = str.zfill('0',2)
        resultType = self.file_data.get('resultType')
        qryReason = self.file_data.get('qryReason')
        queryControlWarningType = self.file_data.get('queryControlWarningType')
        serialNumber = self.file_data.get('serialNumber')
        checkId = self.per_inquire()
        archiveId = self.id
        rekUser = self.file_data.get('rekUser')
        checkWay = self.file_data.get('checkWay')
        autharchiveId = archiveId
        ret = PerReportRequest.per_show_report(clientName, certType, certNo, assocbsnssData, note, queryFormat,
                                               resultType,
                                               qryReason, queryControlWarningType, serialNumber, archiveId,
                                               autharchiveId, checkId,
                                               rekUser, checkWay, self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.url)










if __name__ == "__main__":
    pass